package resources.teacher;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import model.teacher.Department;
import dao.Linker;
import dao.TeacherDAO;

public class TeachersRes
{
	@Context
	UriInfo uriInfo;
	
	@Context
	Request request;
	
	String departmentId;
	
	public TeachersRes(UriInfo uriInfo, Request request, String departmentId) 
	{
		this.uriInfo = uriInfo;
		this.request = request;
		this.departmentId = departmentId;
	}
	
	@GET
	@Produces(MediaType.TEXT_XML)
	public Department getDataBrowser() 
	{
		Linker.sort();
		
		Department department = TeacherDAO.getDepartmentsWithTeachersCP().get(departmentId);
		
		if(department == null)
			throw new RuntimeException("Get: Department with teachers " + departmentId + " not found");
		return department;
	}
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public Department getDataBrowserJSON() 
	{
		return getDataBrowser(); 
	}
	
	@GET
	@Produces(MediaType.APPLICATION_XHTML_XML)
	public Department getDataBrowserXHTML() 
	{
		return getDataBrowser(); 
	}
	
	@GET
	@Produces(MediaType.APPLICATION_XML)
	public Department getDataBrowserXML() 
	{
		return getDataBrowser(); 
	}
	
	@Path("{schedule}")
	public ScheduleRes getGroup(@PathParam("schedule") String id) 
	{
		return new ScheduleRes(uriInfo, request, id);
	}
}